
function checkFieldsEmptyIndex(listValue, index){
	
	var good = true;
	
	for(var i= 0; i < listValue.length; i++)
	{
		var val = listValue[i];
		var fieldValue = document.getElementById(val + index);

		if(fieldValue.value == null || fieldValue.value == "")
		{
			fieldValue.style.border = 'red 1px solid';
			fieldValue.style.backgroundColor = '#FDF1B8';
			if(good)
				good = false;
		}else{
			fieldValue.style.border = '';
			fieldValue.style.backgroundColor = '';
		}

	}


	if(!good)
	{
		alert("Certains éléments obligatoires sont manquants");
	}

	return good;

}

function checkFieldsEmpty(listValue){
	return checkFieldsEmptyIndex(listValue, "")
}

function checkFieldsNumericNotNullIndex(listValue, index){
	
	var good = true;
	
	for(var i= 0; i < listValue.length; i++)
	{
		var val = listValue[i];
		var fieldValue = document.getElementById(val + index);

		if(fieldValue.value == null || isNaN(fieldValue.value))
		{
			fieldValue.style.border = 'red 2px solid';
			fieldValue.style.backgroundColor = '#FDF1B8';
			if(good)
				good = false;
		}else{
			fieldValue.style.border = '';
			fieldValue.style.backgroundColor = '';
		}

	}


	if(!good)
	{
		alert("Certains éléments sont incomplet ou incorrect");
	}

	return good;

}

function checkFieldsNumericNotNull(listValue)
{
	
	return checkFieldsNumericNotNullIndex(listValue, "")
}


function checkFieldsNumericIndex(listValue, index){
	
	var good = true;
	
	for(var i= 0; i < listValue.length; i++)
	{
		var val = listValue[i];
		var fieldValue = document.getElementById(val + index);

		if(fieldValue.value == null || fieldValue.value ==  0 || isNaN(fieldValue.value))
		{
			fieldValue.style.border = 'red 2px solid';
			fieldValue.style.backgroundColor = '#FDF1B8';
			if(good)
				good = false;
		}else{
			fieldValue.style.border = '';
			fieldValue.style.backgroundColor = '';
		}

	}


	if(!good)
	{
		alert("Certains éléments sont incomplet ou incorrect");
	}

	return good;

}

function checkFieldsNumeric(listValue){
	return checkFieldsNumericIndex(listValue, "")
}

function checkPourcentageIndex(listValue, index){
	
	var good = true;
	
	for(var i= 0; i < listValue.length; i++)
	{
		var val = listValue[i];
		var fieldValue = document.getElementById(val + index);

		if(fieldValue.value < 0 || fieldValue.value >  100)
		{
			fieldValue.style.border = 'red 2px solid';
			fieldValue.style.backgroundColor = '#FDF1B8';
			if(good)
				good = false;
		}else{
			fieldValue.style.border = '';
			fieldValue.style.backgroundColor = '';
		}
	}


	if(!good)
	{
		alert("Un pourcentage doit avoir une valeur comprise entre 0 et 100");
	}

	return good;

}

function checkPourcentage(listValue){
	 return checkPourcentageIndex(listValue, "");
}

function checkDate(){

	var ok = true;
	var year = document.getElementById("annee_naissance").value;
	var month =  document.getElementById("mois_naissance").value;
	var day =  document.getElementById("jour_naissance").value;

	ok = verifDate(parseInt(year,10),parseInt(month,10), parseInt(day,10));

	if(!ok)
	{
		alert("la date de naissance n'est pas valide : " + document.getElementById("jour_naissance").value + "/" + document.getElementById("mois_naissance").value + "/"  + document.getElementById("annee_naissance").value);
	}

	return ok;
}

function verifDate(a,m,j){ 
	 m-=1;
	 d=new Date(a,m,j);
	 return (d.getFullYear()!=a || d.getMonth()!=m) ? false : true;
}

function checkFieldsMdpEquals()
{
	
	var pwd = document.getElementById("mdp").value;
	var new_pwd = document.getElementById("new_mdp").value;
	var new_pwd2 = document.getElementById("check_new_mdp").value;


	if(pwd != null && pwd != "")
	{
		if(new_pwd != new_pwd2)
		{
			alert("Les 2 mots de passe ne correspondent pas");
			return false;
		}
	}

	return true;

}
